<template>
	<view class="pending">
		<image src="/static/payinprogress.png" mode="widthFix"></image>
		<p>PAYMENT IN PROGRESS</p>
		<text>Coming soon to stay at your desired homestay</text>
		<!-- <button @click.stop="handleTrip">VIEW ORDER DETAILS</button> -->
	</view>
</template>
<script>
	import {
		getPayStatus
	} from "@/lib/service.js"
	import web from "@/utils/uni.webview.1.5.4.js"
	const webView = web.webView;
	export default {
		data() {
			return {
				orderno: "",
				intervalId: null
			}
		},
		onLoad(options) {
			this.orderno = options.orderno;
		},
		onShow() {
			let _this = this;
			_this.handlePayStatus()
			this.intervalId = setInterval(() => {
				_this.handlePayStatus()
			}, 3000)
		},
		onHide() {
			// 在页面隐藏时清除定时器，防止资源浪费
			if (this.intervalId) {
				clearInterval(this.intervalId);
			}
		},
		methods: {
			handlePayStatus() {
				getPayStatus({
					orderno: this.orderno
				}).then(res => {
					if (res.data.result == 1) {
						uni.redirectTo({
							url: "/pages/index/reserve/success"
						})
					}
				}).catch(err => {

				})

			},
			handleTrip() {
				let message = {
					type: 'success',
					// url: "/pages/index/reserve/my-trip"
					url: "/pages/user/my-order/orders"
				};
				webView.postMessage(message);

			}
		}
	}
</script>

<style>
	.u-icon--right {
		justify-content: center;
	}
</style>
<style lang="scss" scoped>
	.pending {
		text-align: center;
		margin-top: 300rpx;

		image {
			width: 530rpx;
		}

		p {
			margin-top: 50rpx;
			font-family: Microsoft YaHei UI;
			font-weight: 400;
			font-size: 42rpx;
			color: #333333;
		}

		text {
			display: block;
			margin-top: 40rpx;
			font-size: 28rpx;
			color: #999999;
		}

		button {
			width: 630rpx;
			height: 90rpx;
			background: #4980F7;
			border-radius: 45rpx;
			font-size: 32rpx;
			color: #FEFEFE;
			line-height: 90rpx;
			text-align: center;
			margin-top: 70rpx;
		}
	}
</style>